﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestPaper
{
	class ChoiceClass : FlowLayoutPanel
	{
		private Label question;
		private List<RadioButton> answer;
		private int rightAnswer;
		private int answerNum;
		
		public ChoiceClass(string str,int right)
		{
			question = new Label();
			question.Text=str;
			question.AutoSize = true;
			question.Margin=new Padding(0,10,0,0);

			answer = new List<RadioButton>();
			answerNum = 0;
			rightAnswer = right;
			
			this.FlowDirection = FlowDirection.TopDown;
			this.WrapContents=false;
			this.AutoSize=true;
			this.Controls.Add(question);
		}
		
		public void AddQuestion(string str)
		{
			answer.Add(new RadioButton());
			answer.Last().Text=str;
			answer.Last().AutoSize=true;
			answer.Last().Margin=new Padding(0);
			this.Controls.Add(answer[answerNum]);
			answerNum++;
		}
		
		public int GetChoice()
		{
			for (int i = 0; i < answer.Count; i++)
			{
				if(answer[i].Checked) return i;
			}
			return -1;
		}
		
		public int GetScore()
		{
			int choice=GetChoice();
			if(choice<0) return -1;
			else if(choice==rightAnswer) return 1;
			else return 0;
		}
	}
}
